package io.github.lee.jel.domain

import android.content.Context
import android.graphics.drawable.Drawable
import android.widget.ImageView
import androidx.annotation.Keep
import androidx.core.net.toUri
import androidx.databinding.BindingAdapter
import coil.transform.RoundedCornersTransformation
import com.google.gson.annotations.SerializedName
import io.github.lee.core.ui.ba.coilLoad
import io.github.lee.core.util.toPx
import io.github.lee.jel.global.session
import kotlin.math.roundToInt

@BindingAdapter(
    value = ["loadItemDetailBackdrop", "crossfade_time", "placeholder_res", "error_res"],
    requireAll = false
)
fun ImageView.loadItemDetailBackdrop(
    detail: ItemDetail?,
    crossfade: Int? = null,
    placeholder: Drawable? = null,
    error: Drawable? = null
) {
    coilLoad(detail?.fullBackdropImage(context), crossfade, placeholder, error)
}

@BindingAdapter(
    value = ["loadPeopleAvatar", "crossfade_time", "placeholder_res", "error_res"],
    requireAll = false
)
fun ImageView.loadPeopleAvatar(
    people: People?,
    crossfade: Int? = null,
    placeholder: Drawable? = null,
    error: Drawable? = null
) {
    val t = RoundedCornersTransformation(8.toPx(context) * 1.0F)
    coilLoad(people?.fullAvatar(context), crossfade, placeholder, error, t)
}

@Keep
data class ItemDetail(
    @SerializedName("AirDays")
    val airDays: List<String>? = listOf(),
    @SerializedName("AirTime")
    val airTime: String? = "",
    @SerializedName("AirsAfterSeasonNumber")
    val airsAfterSeasonNumber: Int? = 0,
    @SerializedName("AirsBeforeEpisodeNumber")
    val airsBeforeEpisodeNumber: Int? = 0,
    @SerializedName("AirsBeforeSeasonNumber")
    val airsBeforeSeasonNumber: Int? = 0,
    @SerializedName("Album")
    val album: String? = "",
    @SerializedName("AlbumArtist")
    val albumArtist: String? = "",
    @SerializedName("AlbumArtists")
    val albumArtists: List<AlbumArtist>? = listOf(),
    @SerializedName("AlbumCount")
    val albumCount: Int? = 0,
    @SerializedName("AlbumId")
    val albumId: String? = "",
    @SerializedName("AlbumPrimaryImageTag")
    val albumPrimaryImageTag: String? = "",
    @SerializedName("Altitude")
    val altitude: Int? = 0,
    @SerializedName("Aperture")
    val aperture: Int? = 0,
    @SerializedName("ArtistCount")
    val artistCount: Int? = 0,
    @SerializedName("ArtistItems")
    val artistItems: List<ArtistItem>? = listOf(),
    @SerializedName("Artists")
    val artists: List<String>? = listOf(),
    @SerializedName("AspectRatio")
    val aspectRatio: String? = "",
    @SerializedName("Audio")
    val audio: String? = "",
    @SerializedName("BackdropImageTags")
    val backdropImageTags: List<String>? = listOf(),
    @SerializedName("CameraMake")
    val cameraMake: String? = "",
    @SerializedName("CameraModel")
    val cameraModel: String? = "",
    @SerializedName("CanDelete")
    val canDelete: Boolean? = false,
    @SerializedName("CanDownload")
    val canDownload: Boolean? = false,
    @SerializedName("ChannelId")
    val channelId: String? = "",
    @SerializedName("ChannelName")
    val channelName: String? = "",
    @SerializedName("ChannelNumber")
    val channelNumber: String? = "",
    @SerializedName("ChannelPrimaryImageTag")
    val channelPrimaryImageTag: String? = "",
    @SerializedName("ChannelType")
    val channelType: String? = "",
    @SerializedName("Chapters")
    val chapters: List<Chapter>? = listOf(),
    @SerializedName("ChildCount")
    val childCount: Int? = 0,
    @SerializedName("CollectionType")
    val collectionType: String? = "",
    @SerializedName("CommunityRating")
    val communityRating: Double? = 0.0,
    @SerializedName("CompletionPercentage")
    val completionPercentage: Int? = 0,
    @SerializedName("Container")
    val container: String? = "",
    @SerializedName("CriticRating")
    val criticRating: Int? = 0,
    @SerializedName("CumulativeRunTimeTicks")
    val cumulativeRunTimeTicks: Long? = 0,
    @SerializedName("CurrentProgram")
    val currentProgram: CurrentProgram? = CurrentProgram(),
    @SerializedName("CustomRating")
    val customRating: String? = "",
    @SerializedName("DateCreated")
    val dateCreated: String? = "",
    @SerializedName("DateLastMediaAdded")
    val dateLastMediaAdded: String? = "",
    @SerializedName("DisplayOrder")
    val displayOrder: String? = "",
    @SerializedName("DisplayPreferencesId")
    val displayPreferencesId: String? = "",
    @SerializedName("EnableMediaSourceDisplay")
    val enableMediaSourceDisplay: Boolean? = false,
    @SerializedName("EndDate")
    val endDate: String? = "",
    @SerializedName("EpisodeCount")
    val episodeCount: Int? = 0,
    @SerializedName("EpisodeTitle")
    val episodeTitle: String? = "",
    @SerializedName("Etag")
    val etag: String? = "",
    @SerializedName("ExposureTime")
    val exposureTime: Int? = 0,
    @SerializedName("ExternalUrls")
    val externalUrls: List<ExternalUrl>? = listOf(),
    @SerializedName("ExtraType")
    val extraType: String? = "",
    @SerializedName("FocalLength")
    val focalLength: Int? = 0,
    @SerializedName("ForcedSortName")
    val forcedSortName: String? = "",
    @SerializedName("GenreItems")
    val genreItems: List<GenreItem>? = listOf(),
    @SerializedName("Genres")
    val genres: List<String>? = listOf(),
    @SerializedName("HasSubtitles")
    val hasSubtitles: Boolean? = false,
    @SerializedName("Height")
    val height: Int? = 0,
    @SerializedName("Id")
    val id: String? = "",
    @SerializedName("ImageBlurHashes")
    val imageBlurHashes: ImageBlurHashes? = ImageBlurHashes(),
    @SerializedName("ImageOrientation")
    val imageOrientation: String? = "",
    @SerializedName("ImageTags")
    val imageTags: ImageTags? = ImageTags(),
    @SerializedName("IndexNumber")
    val indexNumber: Int? = 0,
    @SerializedName("IndexNumberEnd")
    val indexNumberEnd: Int? = 0,
    @SerializedName("IsFolder")
    val isFolder: Boolean? = false,
    @SerializedName("IsHD")
    val isHD: Boolean? = false,
    @SerializedName("IsKids")
    val isKids: Boolean? = false,
    @SerializedName("IsLive")
    val isLive: Boolean? = false,
    @SerializedName("IsMovie")
    val isMovie: Boolean? = false,
    @SerializedName("IsNews")
    val isNews: Boolean? = false,
    @SerializedName("IsPlaceHolder")
    val isPlaceHolder: Boolean? = false,
    @SerializedName("IsPremiere")
    val isPremiere: Boolean? = false,
    @SerializedName("IsRepeat")
    val isRepeat: Boolean? = false,
    @SerializedName("IsSeries")
    val isSeries: Boolean? = false,
    @SerializedName("IsSports")
    val isSports: Boolean? = false,
    @SerializedName("IsoSpeedRating")
    val isoSpeedRating: Int? = 0,
    @SerializedName("IsoType")
    val isoType: String? = "",
    @SerializedName("Latitude")
    val latitude: Int? = 0,
    @SerializedName("LocalTrailerCount")
    val localTrailerCount: Int? = 0,
    @SerializedName("LocationType")
    val locationType: String? = "",
    @SerializedName("LockData")
    val lockData: Boolean? = false,
    @SerializedName("LockedFields")
    val lockedFields: List<String>? = listOf(),
    @SerializedName("Longitude")
    val longitude: Int? = 0,
    @SerializedName("MediaSourceCount")
    val mediaSourceCount: Int? = 0,
    @SerializedName("MediaSources")
    val mediaSources: List<MediaSource>? = listOf(),
    @SerializedName("MediaStreams")
    val mediaStreams: List<MediaStreamX>? = listOf(),
    @SerializedName("MediaType")
    val mediaType: String? = "",
    @SerializedName("MovieCount")
    val movieCount: Int? = 0,
    @SerializedName("MusicVideoCount")
    val musicVideoCount: Int? = 0,
    @SerializedName("Name")
    val name: String? = "",
    @SerializedName("Number")
    val number: String? = "",
    @SerializedName("OfficialRating")
    val officialRating: String? = "",
    @SerializedName("OriginalTitle")
    val originalTitle: String? = "",
    @SerializedName("Overview")
    val overview: String? = "",
    @SerializedName("ParentArtImageTag")
    val parentArtImageTag: String? = "",
    @SerializedName("ParentArtItemId")
    val parentArtItemId: String? = "",
    @SerializedName("ParentBackdropImageTags")
    val parentBackdropImageTags: List<String>? = listOf(),
    @SerializedName("ParentBackdropItemId")
    val parentBackdropItemId: String? = "",
    @SerializedName("ParentId")
    val parentId: String? = "",
    @SerializedName("ParentIndexNumber")
    val parentIndexNumber: Int? = 0,
    @SerializedName("ParentLogoImageTag")
    val parentLogoImageTag: String? = "",
    @SerializedName("ParentLogoItemId")
    val parentLogoItemId: String? = "",
    @SerializedName("ParentPrimaryImageItemId")
    val parentPrimaryImageItemId: String? = "",
    @SerializedName("ParentPrimaryImageTag")
    val parentPrimaryImageTag: String? = "",
    @SerializedName("ParentThumbImageTag")
    val parentThumbImageTag: String? = "",
    @SerializedName("ParentThumbItemId")
    val parentThumbItemId: String? = "",
    @SerializedName("PartCount")
    val partCount: Int? = 0,
    @SerializedName("Path")
    val path: String? = "",
    @SerializedName("People")
    val people: List<People>? = listOf(),
    @SerializedName("PlayAccess")
    val playAccess: String? = "",
    @SerializedName("PlaylistItemId")
    val playlistItemId: String? = "",
    @SerializedName("PreferredMetadataCountryCode")
    val preferredMetadataCountryCode: String? = "",
    @SerializedName("PreferredMetadataLanguage")
    val preferredMetadataLanguage: String? = "",
    @SerializedName("PremiereDate")
    val premiereDate: String? = "",
    @SerializedName("PrimaryImageAspectRatio")
    val primaryImageAspectRatio: Double? = 0.0,
    @SerializedName("ProductionLocations")
    val productionLocations: List<String>? = listOf(),
    @SerializedName("ProductionYear")
    val productionYear: Int? = 0,
    @SerializedName("ProgramCount")
    val programCount: Int? = 0,
    @SerializedName("ProgramId")
    val programId: String? = "",
    @SerializedName("ProviderIds")
    val providerIds: ProviderIds? = ProviderIds(),
    @SerializedName("RecursiveItemCount")
    val recursiveItemCount: Int? = 0,
    @SerializedName("RemoteTrailers")
    val remoteTrailers: List<RemoteTrailer>? = listOf(),
    @SerializedName("RunTimeTicks")
    val runTimeTicks: Long? = 0,
    @SerializedName("ScreenshotImageTags")
    val screenshotImageTags: List<String>? = listOf(),
    @SerializedName("SeasonId")
    val seasonId: String? = "",
    @SerializedName("SeasonName")
    val seasonName: String? = "",
    @SerializedName("SeriesCount")
    val seriesCount: Int? = 0,
    @SerializedName("SeriesId")
    val seriesId: String? = "",
    @SerializedName("SeriesName")
    val seriesName: String? = "",
    @SerializedName("SeriesPrimaryImageTag")
    val seriesPrimaryImageTag: String? = "",
    @SerializedName("SeriesStudio")
    val seriesStudio: String? = "",
    @SerializedName("SeriesThumbImageTag")
    val seriesThumbImageTag: String? = "",
    @SerializedName("SeriesTimerId")
    val seriesTimerId: String? = "",
    @SerializedName("ServerId")
    val serverId: String? = "",
    @SerializedName("ShutterSpeed")
    val shutterSpeed: Int? = 0,
    @SerializedName("Software")
    val software: String? = "",
    @SerializedName("SongCount")
    val songCount: Int? = 0,
    @SerializedName("SortName")
    val sortName: String? = "",
    @SerializedName("SourceType")
    val sourceType: String? = "",
    @SerializedName("SpecialFeatureCount")
    val specialFeatureCount: Int? = 0,
    @SerializedName("StartDate")
    val startDate: String? = "",
    @SerializedName("Status")
    val status: String? = "",
    @SerializedName("Studios")
    val studios: List<Studio>? = listOf(),
    @SerializedName("SupportsSync")
    val supportsSync: Boolean? = false,
    @SerializedName("Taglines")
    val taglines: List<String>? = listOf(),
    @SerializedName("Tags")
    val tags: List<String>? = listOf(),
    @SerializedName("TimerId")
    val timerId: String? = "",
    @SerializedName("TrailerCount")
    val trailerCount: Int? = 0,
    @SerializedName("Type")
    val type: String? = "",
    @SerializedName("UserData")
    val userData: UserData? = UserData(),
    @SerializedName("Video3DFormat")
    val video3DFormat: String? = "",
    @SerializedName("VideoType")
    val videoType: String? = "",
    @SerializedName("Width")
    val width: Int? = 0
) {
    fun fullPrimaryImage(context: Context): String {
        return context.session?.address?.toUri()?.buildUpon()
            ?.appendEncodedPath("Items/$id/Images/Primary")
            ?.appendQueryParameter("tag", imageTags?.primary)
            ?.build().toString()
    }

    fun fullBackdropImage(context: Context): String {
        val tag = if (backdropImageTags.isNullOrEmpty()) {
            ""
        } else {
            backdropImageTags.get(0)
        }
        val build = context.session?.address?.toUri()?.buildUpon()
            ?.appendEncodedPath("Items/$id/Images/Backdrop/0")
        if (tag.isNotEmpty()) {
            build?.appendQueryParameter("tag", tag)
        }
        return build?.build().toString()
    }

    fun getTotalMinute(): Int {
        val s = runTimeTicks.toString()
        val total = if (s.length == 11) {
            (runTimeTicks ?: 0) / 10
        } else {
            runTimeTicks ?: 0
        }
        return (total * 1.0 / 1000 / 1000 / 60).roundToInt()
    }

    fun formatType(): String {
        val sb = StringBuilder()
        genreItems?.forEachIndexed { index, it ->
            sb.append(it.name)
            if (index < genreItems.size - 1) {
                sb.append(", ")
            }
        }
        return sb.toString()
    }
}

@Keep
data class AlbumArtist(
    @SerializedName("Id")
    val id: String? = "",
    @SerializedName("Name")
    val name: String? = ""
)

@Keep
data class ArtistItem(
    @SerializedName("Id")
    val id: String? = "",
    @SerializedName("Name")
    val name: String? = ""
)

@Keep
data class Chapter(
    @SerializedName("ImageDateModified")
    val imageDateModified: String? = "",
    @SerializedName("ImagePath")
    val imagePath: String? = "",
    @SerializedName("ImageTag")
    val imageTag: String? = "",
    @SerializedName("Name")
    val name: String? = "",
    @SerializedName("StartPositionTicks")
    val startPositionTicks: Long? = 0
)

@Keep
class CurrentProgram

@Keep
data class ExternalUrl(
    @SerializedName("Name")
    val name: String? = "",
    @SerializedName("Url")
    val url: String? = ""
)

@Keep
data class GenreItem(
    @SerializedName("Id")
    val id: String? = "",
    @SerializedName("Name")
    val name: String? = ""
)

@Keep
data class ImageBlurHashes(
    @SerializedName("Art")
    val art: Art? = Art(),
    @SerializedName("Backdrop")
    val backdrop: Backdrop? = Backdrop(),
    @SerializedName("Banner")
    val banner: Banner? = Banner(),
    @SerializedName("Box")
    val box: Box? = Box(),
    @SerializedName("BoxRear")
    val boxRear: BoxRear? = BoxRear(),
    @SerializedName("Chapter")
    val chapter: ChapterX? = ChapterX(),
    @SerializedName("Disc")
    val disc: Disc? = Disc(),
    @SerializedName("Logo")
    val logo: Logo? = Logo(),
    @SerializedName("Menu")
    val menu: Menu? = Menu(),
    @SerializedName("Primary")
    val primary: Primary? = Primary(),
    @SerializedName("Profile")
    val profile: Profile? = Profile(),
    @SerializedName("Screenshot")
    val screenshot: Screenshot? = Screenshot(),
    @SerializedName("Thumb")
    val thumb: Thumb? = Thumb()
)


@Keep
data class MediaSource(
    @SerializedName("AnalyzeDurationMs")
    val analyzeDurationMs: Int? = 0,
    @SerializedName("Bitrate")
    val bitrate: Int? = 0,
    @SerializedName("BufferMs")
    val bufferMs: Int? = 0,
    @SerializedName("Container")
    val container: String? = "",
    @SerializedName("DefaultAudioStreamIndex")
    val defaultAudioStreamIndex: Int? = 0,
    @SerializedName("DefaultSubtitleStreamIndex")
    val defaultSubtitleStreamIndex: Int? = 0,
    @SerializedName("ETag")
    val eTag: String? = "",
    @SerializedName("EncoderPath")
    val encoderPath: String? = "",
    @SerializedName("EncoderProtocol")
    val encoderProtocol: String? = "",
    @SerializedName("Formats")
    val formats: List<String>? = listOf(),
    @SerializedName("GenPtsInput")
    val genPtsInput: Boolean? = false,
    @SerializedName("Id")
    val id: String? = "",
    @SerializedName("IgnoreDts")
    val ignoreDts: Boolean? = false,
    @SerializedName("IgnoreIndex")
    val ignoreIndex: Boolean? = false,
    @SerializedName("IsInfiniteStream")
    val isInfiniteStream: Boolean? = false,
    @SerializedName("IsRemote")
    val isRemote: Boolean? = false,
    @SerializedName("IsoType")
    val isoType: String? = "",
    @SerializedName("LiveStreamId")
    val liveStreamId: String? = "",
    @SerializedName("MediaAttachments")
    val mediaAttachments: List<MediaAttachment>? = listOf(),
    @SerializedName("MediaStreams")
    val mediaStreams: List<MediaStreamX>? = listOf(),
    @SerializedName("Name")
    val name: String? = "",
    @SerializedName("OpenToken")
    val openToken: String? = "",
    @SerializedName("Path")
    val path: String? = "",
    @SerializedName("Protocol")
    val protocol: String? = "",
    @SerializedName("ReadAtNativeFramerate")
    val readAtNativeFramerate: Boolean? = false,
    @SerializedName("RequiredHttpHeaders")
    val requiredHttpHeaders: RequiredHttpHeaders? = RequiredHttpHeaders(),
    @SerializedName("RequiresClosing")
    val requiresClosing: Boolean? = false,
    @SerializedName("RequiresLooping")
    val requiresLooping: Boolean? = false,
    @SerializedName("RequiresOpening")
    val requiresOpening: Boolean? = false,
    @SerializedName("RunTimeTicks")
    val runTimeTicks: Long? = 0,
    @SerializedName("Size")
    val size: Long? = 0,
    @SerializedName("SupportsDirectPlay")
    val supportsDirectPlay: Boolean? = false,
    @SerializedName("SupportsDirectStream")
    val supportsDirectStream: Boolean? = false,
    @SerializedName("SupportsProbing")
    val supportsProbing: Boolean? = false,
    @SerializedName("SupportsTranscoding")
    val supportsTranscoding: Boolean? = false,
    @SerializedName("Timestamp")
    val timestamp: String? = "",
    @SerializedName("TranscodingContainer")
    val transcodingContainer: String? = "",
    @SerializedName("TranscodingSubProtocol")
    val transcodingSubProtocol: String? = "",
    @SerializedName("TranscodingUrl")
    val transcodingUrl: String? = "",
    @SerializedName("Type")
    val type: String? = "",
    @SerializedName("Video3DFormat")
    val video3DFormat: String? = "",
    @SerializedName("VideoType")
    val videoType: String? = ""
)

@Keep
data class MediaStreamX(
    @SerializedName("AspectRatio")
    val aspectRatio: String? = "",
    @SerializedName("AverageFrameRate")
    val averageFrameRate: Double? = 0.0,
    @SerializedName("BitDepth")
    val bitDepth: Int? = 0,
    @SerializedName("BitRate")
    val bitRate: Int? = 0,
    @SerializedName("BlPresentFlag")
    val blPresentFlag: Int? = 0,
    @SerializedName("ChannelLayout")
    val channelLayout: String? = "",
    @SerializedName("Channels")
    val channels: Int? = 0,
    @SerializedName("Codec")
    val codec: String? = "",
    @SerializedName("CodecTag")
    val codecTag: String? = "",
    @SerializedName("CodecTimeBase")
    val codecTimeBase: String? = "",
    @SerializedName("ColorPrimaries")
    val colorPrimaries: String? = "",
    @SerializedName("ColorRange")
    val colorRange: String? = "",
    @SerializedName("ColorSpace")
    val colorSpace: String? = "",
    @SerializedName("ColorTransfer")
    val colorTransfer: String? = "",
    @SerializedName("Comment")
    val comment: String? = "",
    @SerializedName("DeliveryMethod")
    val deliveryMethod: String? = "",
    @SerializedName("DeliveryUrl")
    val deliveryUrl: String? = "",
    @SerializedName("DisplayTitle")
    val displayTitle: String? = "",
    @SerializedName("DvBlSignalCompatibilityId")
    val dvBlSignalCompatibilityId: Int? = 0,
    @SerializedName("DvLevel")
    val dvLevel: Int? = 0,
    @SerializedName("DvProfile")
    val dvProfile: Int? = 0,
    @SerializedName("DvVersionMajor")
    val dvVersionMajor: Int? = 0,
    @SerializedName("DvVersionMinor")
    val dvVersionMinor: Int? = 0,
    @SerializedName("ElPresentFlag")
    val elPresentFlag: Int? = 0,
    @SerializedName("Height")
    val height: Int? = 0,
    @SerializedName("Index")
    val index: Int? = 0,
    @SerializedName("IsAVC")
    val isAVC: Boolean? = false,
    @SerializedName("IsAnamorphic")
    val isAnamorphic: Boolean? = false,
    @SerializedName("IsDefault")
    val isDefault: Boolean? = false,
    @SerializedName("IsExternal")
    val isExternal: Boolean? = false,
    @SerializedName("IsExternalUrl")
    val isExternalUrl: Boolean? = false,
    @SerializedName("IsForced")
    val isForced: Boolean? = false,
    @SerializedName("IsInterlaced")
    val isInterlaced: Boolean? = false,
    @SerializedName("IsTextSubtitleStream")
    val isTextSubtitleStream: Boolean? = false,
    @SerializedName("Language")
    val language: String? = "",
    @SerializedName("Level")
    val level: Int? = 0,
    @SerializedName("LocalizedDefault")
    val localizedDefault: String? = "",
    @SerializedName("LocalizedExternal")
    val localizedExternal: String? = "",
    @SerializedName("LocalizedForced")
    val localizedForced: String? = "",
    @SerializedName("LocalizedUndefined")
    val localizedUndefined: String? = "",
    @SerializedName("NalLengthSize")
    val nalLengthSize: String? = "",
    @SerializedName("PacketLength")
    val packetLength: Int? = 0,
    @SerializedName("Path")
    val path: String? = "",
    @SerializedName("PixelFormat")
    val pixelFormat: String? = "",
    @SerializedName("Profile")
    val profile: String? = "",
    @SerializedName("RealFrameRate")
    val realFrameRate: Double? = 0.0,
    @SerializedName("RefFrames")
    val refFrames: Int? = 0,
    @SerializedName("RpuPresentFlag")
    val rpuPresentFlag: Int? = 0,
    @SerializedName("SampleRate")
    val sampleRate: Double? = 0.0,
    @SerializedName("Score")
    val score: Int? = 0,
    @SerializedName("SupportsExternalStream")
    val supportsExternalStream: Boolean? = false,
    @SerializedName("TimeBase")
    val timeBase: String? = "",
    @SerializedName("Title")
    val title: String? = "",
    @SerializedName("Type")
    val type: String? = "",
    @SerializedName("VideoDoViTitle")
    val videoDoViTitle: String? = "",
    @SerializedName("VideoRange")
    val videoRange: String? = "",
    @SerializedName("VideoRangeType")
    val videoRangeType: String? = "",
    @SerializedName("Width")
    val width: Int? = 0
)


@Keep
data class People(
    @SerializedName("Id")
    val id: String? = "",
    @SerializedName("Name")
    val name: String? = "",
    @SerializedName("PrimaryImageTag")
    val primaryImageTag: String? = "",
    @SerializedName("Role")
    val role: String? = "",
    @SerializedName("Type")
    val type: String? = ""
) {
    fun fullAvatar(context: Context): String {
        return context.session?.address?.toUri()?.buildUpon()
            ?.appendEncodedPath("Items/$id/Images/Primary")
            ?.appendQueryParameter("tag", primaryImageTag)
            ?.build()?.toString() ?: ""
    }
}

@Keep
data class ProviderIds(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class RemoteTrailer(
    @SerializedName("Name")
    val name: String? = "",
    @SerializedName("Url")
    val url: String? = ""
)

@Keep
data class Studio(
    @SerializedName("Id")
    val id: String? = "",
    @SerializedName("Name")
    val name: String? = ""
)


@Keep
data class Art(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class Backdrop(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class Banner(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class Box(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class BoxRear(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class ChapterX(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class Disc(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class Logo(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class Menu(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class Primary(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class Profile(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class Screenshot(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class Thumb(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)

@Keep
data class MediaAttachment(
    @SerializedName("Codec")
    val codec: String? = "",
    @SerializedName("CodecTag")
    val codecTag: String? = "",
    @SerializedName("Comment")
    val comment: String? = "",
    @SerializedName("DeliveryUrl")
    val deliveryUrl: String? = "",
    @SerializedName("FileName")
    val fileName: String? = "",
    @SerializedName("Index")
    val index: Int? = 0,
    @SerializedName("MimeType")
    val mimeType: String? = ""
)

@Keep
data class RequiredHttpHeaders(
    @SerializedName("property1")
    val property1: String? = "",
    @SerializedName("property2")
    val property2: String? = ""
)
